﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication3
{
    public partial class FormDataView : FormBase
    {
        public FormDataView()
        {
            InitializeComponent();
        }

        public FormDataView(ToolStripMenuItem tsMi)
            : base(tsMi)
        {
            InitializeComponent();
            WindowState = FormWindowState.Maximized;
        }

        private void FormStuBaseInfo_Load(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider=SQLOLEDB;Data Source=.;Integrated Security=SSPI;Initial Catalog=master";
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select * from student;";

            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = cmd;

            DataTable dt = new DataTable();
            adapter.Fill(dt);

            BindingSource bs = new BindingSource();
            DataView dv = new DataView(dt, "sex = '男'", "age", DataViewRowState.CurrentRows);
            bs.DataSource = dv;
            dataGridView1.DataSource = bs;

            bs = new BindingSource();
            dv = new DataView(dt, "sex = '女'", "sname desc", DataViewRowState.CurrentRows);
            bs.DataSource = dv;
            dataGridView2.DataSource = bs;
        }
    }
}
